<?php

namespace StudyBuddy;

/**
 * Static class for replacing bad words
 * in string with *** or something else (like UTF8 Art)
 *
 */
class Badwords {

    protected static $aStopwords = array(
        ' sex',
        'cvv',
        'ccv',
        'skimmer',
        'skimmed',
        'bank login',
        'dumps',
        'fullz',
        'fuck',
        'horny',
        'milf',
        'erotic',
        ' cum ',
        ' cunt',
        'vagina',
        'interracial',
        'pussy',
        ' cock',
        'blowjob',
        'naked',
        'nude',
        ' tits',
        'titty',
        'porn',
        'adult',
        'viagra',
        'hack',
        'crack',
        'slut',
        'lolita',
        'gambl',
        'poker',
        'pharmacy',
        'incest',
        'warez');

    /**
     * Static getter for badwords array
     *
     * return array
     */
    public static function getBadwords() {

        return self::$aStopwords;
    }

    public static function filter($string, $isBody = false) {

        $link = ($isBody) ? '<a href="#filtered"><sup>1</sup></a>' : '';

        return str_ireplace(self::$aStopwords, '*****' . $link, $string);
    }

    /**
     * Check to see if string contains any bad words
     *
     * @param string $string input string
     *
     * @return int 0 means string is clean
     * The reason to return int instead of true/false is because
     * we can get more information from number of matches.
     * Higher than 1 means it's more likely to be a really
     * bad message.
     */
    public static function getScore($string) {
        str_ireplace(self::$aStopwords, '*', $string, $count);

        return $count;
    }

}
